export default class LocalDate{
    constructor(timestr){
        this.date = new Date(timestr)
    }
    format(formatStr){
        if(!formatStr){
            return null;
        }
        var regx = {
            "M+": this.date.getMonth() + 1, //月份 
            "d+": this.date.getDate(), //日 
            "h+": this.date.getHours() % 12 == 0 ? 12 : this.date.getHours() % 12, //12小时 
            "H+": this.date.getHours(), //24小时 
            "m+": this.date.getMinutes(), //分 
            "s+": this.date.getSeconds(), //秒 
            "q+": Math.floor((this.date.getMonth() + 3) / 3), //季度 
            "S": this.date.getMilliseconds() //毫秒 
        }
        if((new RegExp('(y+)')).test(formatStr)){
            formatStr = formatStr.replace(RegExp.$1,(this.date.getFullYear()+"").substr(4-RegExp.$1.length));
        }
        for(let key in regx){
            if((new RegExp('('+key+')')).test(formatStr)){
                formatStr = formatStr.replace(RegExp.$1,(RegExp.$1.length==1?regx[key]:("00"+regx[key]).substr((""+regx[key]).length)))
            }
        }
        return formatStr;
    }
}